﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Ylh.IDAL;
using System.Data;

namespace Ylh.BLL
{
    public class RoleBLL
    {
        private string ConStr = string.Empty;

        public RoleBLL(string ConStr)
        {
            this.ConStr = ConStr;
        }



        /// <summary>
        /// 执行插入角色,返回插入后的的角色ID
        /// </summary>
        /// <param name="ConStr">指定的数据库</param>
        /// <param name="RoleName">角色名称</param>
        /// <param name="Remark">角色备注</param>
        /// <returns>角色ID</returns>
        public int InsertRole( string RoleName, string Remark, string Creater, string ProtectCount)
        {
            Ylh.IDAL.IRole Role = Ylh.FactoryDAL.DataAccess.CreateIRole();
            return Role.InsertRole(ConStr, RoleName, Remark, Creater, ProtectCount);
        }



        /// <summary>
        /// 更新角色信息
        /// </summary>
        /// <param name="ConStr">指定的数据库</param>
        /// <param name="RoleName">角色名称</param>
        /// <param name="Remark">角色备注</param>
        /// <param name="RoleID">角色编号</param>
        /// <returns>是否更新成功</returns>
        public bool UpdateRole(string RoleName, string Remark, decimal RoleID, string ProtectCount)
        {
            Ylh.IDAL.IRole Role = Ylh.FactoryDAL.DataAccess.CreateIRole();
            return Role.UpdateRole( ConStr,  RoleName,  Remark,  RoleID,  ProtectCount);
        }



        /// <summary>
        /// 判断该名称是否存在
        /// </summary>
        /// <param name="ConStr">指定的数据库</param>
        /// <param name="RoleName">角色名称</param>
        /// <returns></returns>
        public bool IsExistsRole(string RoleName)
        {
            Ylh.IDAL.IRole Role = Ylh.FactoryDAL.DataAccess.CreateIRole();
            return Role.IsExistsRole(ConStr, RoleName);
        }


        /// <summary>
        /// 获取对应的角色信息
        /// 如果RoleID等于-1是获取所有信息
        /// </summary>
        /// <param name="ConStr"></param>
        /// <param name="RoleID"></param>
        /// <returns></returns>
        public DataTable GetRoleInFo(decimal RoleID)
        {
            Ylh.IDAL.IRole Role = Ylh.FactoryDAL.DataAccess.CreateIRole();
            return Role.GetRoleInFo(ConStr, RoleID);

        }

        public void Delete(List<string> li)
        {
            Ylh.IDAL.IRole Role = Ylh.FactoryDAL.DataAccess.CreateIRole();

            foreach (string str in li)
            {
                if (!Role.IsUseByStaff(ConStr, str))
                {
                    continue;
                }
                Role.DeleteRoleByRoleID(ConStr, str);
            }

        }
    }
}
